home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1419 / 1419.xpi / chrome / content / ietabExtApp.js < prev    next >
Text File  |  2009-05-26  |  2KB  |  53 lines

  1. var IeTabExtApp = {
  2.  
  3.    HKEY_CLASSES_ROOT: 0,
  4.    HKEY_CURRENT_CONFIG: 1,
  5.    HKEY_CURRENT_USER: 2,
  6.    HKEY_LOCAL_MACHINE: 3,
  7.    HKEY_USERS: 4,
  8.  
  9.    getRegistryEntry: function(regRoot, regPath, regName) {
  10.       try {
  11.          if ("@mozilla.org/windows-registry-key;1" in Components.classes) {
  12.             var nsIWindowsRegKey = Components.classes["@mozilla.org/windows-registry-key;1"].getService(Components.interfaces.nsIWindowsRegKey);
  13.             var regRootKey = new Array(0x80000000, 0x80000005, 0x80000001, 0x80000002, 0x80000003);
  14.             nsIWindowsRegKey.open(regRootKey[regRoot], regPath, Components.interfaces.nsIWindowsRegKey.ACCESS_READ);
  15.             if (nsIWindowsRegKey.valueCount)
  16.                return nsIWindowsRegKey.readStringValue(regName);
  17.          }
  18.       } catch(e) {}
  19.       return null;
  20.    },
  21.  
  22.    getIExploreExePath: function() {
  23.       var regRoot = this.HKEY_LOCAL_MACHINE;
  24.       var regPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE";
  25.       var regName = "";
  26.       return this.getRegistryEntry(regRoot, regPath, regName);
  27.    },
  28.  
  29.    removeArrayNullElements: function(a) {
  30.       var result = [];
  31.       while(a.length) {
  32.          var elmt = a.shift();
  33.          if (elmt) result.push(elmt);
  34.       }
  35.       return result;
  36.    },
  37.  
  38.    runApp: function(filename, parameter) {
  39.       if ((!filename) || (filename == "")) filename = this.getIExploreExePath();
  40.       var nsILocalFile = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
  41.       nsILocalFile.initWithPath(filename);
  42.       if (nsILocalFile.exists()) {
  43.          var paramArray = parameter ? parameter.split(/\s*\"([^\"]*)\"\s*|\s+/) : [];
  44.          paramArray = this.removeArrayNullElements(paramArray);
  45.          var nsIProcess = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
  46.          nsIProcess.init(nsILocalFile);
  47.          nsIProcess.run(false, paramArray, paramArray.length);
  48.          return true;
  49.       }
  50.       return false;
  51.    }
  52. };
  53.